#include <stdio.h>
#include "system.h"
#include "io.h"
#include "SJA1000_functions.h"
#include "SJA1000.h"
#include "SJA1000_REG.h"

int main()
{
  unsigned int temp;
  int i;
  CAN_PACKAGE pkg;
  
  printf("Hello from Nios II!\n");
  printf("SJA1000 initialing...");
  SJA1000_init();
  printf("done\n");
  pkg.format=1;
  pkg.DLC=8;
  pkg.RTR=0;
  pkg.ID=0xB130;
  pkg.data[0]=0xa0;
  pkg.data[1]=0xa1;
  pkg.data[2]=0xa2;
  pkg.data[3]=0xa3;
  pkg.data[4]=0xa4;
  pkg.data[5]=0xa5;
  pkg.data[6]=0xa6;
  pkg.data[7]=0xa7;
  printf("write");
  getchar();
  SJA1000_write(&pkg);
  while(1)
  {
    SJA1000_read(&pkg);
    printf("ID=%x\n",pkg.ID);
    printf("data= ");
    for(i=0;i<pkg.DLC;i++)
    {
      printf("%c",pkg.data[i]);
    }
    printf("\n");
  }
}